package com.example.myui.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import com.afollestad.materialdialogs.GravityEnum;
import com.afollestad.materialdialogs.MaterialDialog;
import com.blankj.utilcode.util.FileUtils;
import com.example.myui.R;
import com.example.myui.utils.FileUtil;
import com.example.myui.widget.ShareDialog;
import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


public class DialogActivity extends AppCompatActivity {

    private String TAG = DialogActivity.class.getSimpleName();
    private String filePath = Environment.getExternalStorageDirectory() + "/" + "afile.text";

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);

        RxPermissions rxPermissions = new RxPermissions(DialogActivity.this);
        rxPermissions.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new Observer<Permission>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Permission permission) {
                        if (permission.granted) {
                            Toast.makeText(DialogActivity.this, "granted", Toast.LENGTH_SHORT).show();

                        } else {

                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });


        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareDialog dialog = new ShareDialog(DialogActivity.this);
                dialog.setGRAVITY(Gravity.BOTTOM);
                dialog.setConView(R.layout.dialog_share_layout);
                dialog.setPercent(0.8f);
//                dialog.setContentView(R.layout.dialog_share_layout);
                dialog.setCanceledOnTouchOutside(true);
                dialog.show();
            }
        });

        findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareDialog shareDialog = new ShareDialog(DialogActivity.this);
                shareDialog.setGRAVITY(Gravity.CENTER);
                shareDialog.setConView(R.layout.progress_dialog);
                shareDialog.show();
            }
        });

        findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MaterialDialog show = new MaterialDialog.Builder(DialogActivity.this)
                        .title("Title")
                        .titleGravity(GravityEnum.END)
                        .iconRes(R.mipmap.ic_launcher)
                        .customView(R.layout.progress_dialog, true)
//                        .content("content")
                        .show();

            }
        });

        findViewById(R.id.btn4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = Environment.getExternalStorageDirectory().getPath() + "/" + "afile";
                File file = new File(s);
                if (!file.exists()) {
                    file.mkdirs();
                }
                String path = file.getPath();
                String absolutePath = file.getAbsolutePath();
                String fileName = file.getName();
                Log.i(TAG, "onNext: " + path + "absolutePath :" + absolutePath + "fileName :" + fileName);
            }
        });

//        在data/data/包名下创建文件夹
        findViewById(R.id.btn5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + "Android/data/com.example.myui/" + "afile");
                if (!file.exists()) {
                    file.mkdirs();
                }
                Log.i(TAG, "onClick: " + file.getPath());
            }
        });

        findViewById(R.id.btn6).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        findViewById(R.id.btn7).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ShareDialog dialog = new ShareDialog(DialogActivity.this);
                dialog.setGRAVITY(Gravity.CENTER);
                dialog.setConView(R.layout.full_screen_dialog);
                dialog.show();
            }
        });
    }
}
